package com.cne.gmail.Gmail.threadFactory;


import com.cne.gmail.Gmail.Excutor.ScheduledExecutor;
import com.cne.gmail.Gmail.Util.MakeGmailIdsUtil;
import com.cne.gmail.Gmail.model.UserModel;
import com.cne.gmail.Gmail.service.UserService;
import com.google.common.collect.Lists;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class importThread implements Runnable {
    private UserService userService;
    private UserModel user;
    private ScheduledExecutor scheduledExecutor;
    private String label;
    public importThread(UserService userService, UserModel user, ScheduledExecutor scheduledExecutor, String label){
        this.userService=userService;
        this.user=user;
        this.scheduledExecutor=scheduledExecutor;
        this.label=label;

    }
    @Override
    public void run() {
        List<String> labels= Lists.newArrayList();
        labels.add(label);
        List<String> gmailIds= null;
        try {
            gmailIds = MakeGmailIdsUtil.makeGmailIds(user,labels);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Set<String> listToSet = new HashSet<String>(gmailIds);
        try {
            scheduledExecutor.importGmailToMongo(listToSet,label,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
